package m2acsis.algebre.impl;

import java.math.BigDecimal;

import m2acsis.algebre.ElemGroupe;

public class Reel implements ElemGroupe, Comparable<Reel>{

	private BigDecimal n; 
	
	public Reel(double n) {
		this.n = new BigDecimal(String.valueOf(n));
	}
	
	@Override
	public ElemGroupe neutre() {
		return new Reel(0);
	}

	@Override
	public ElemGroupe oppose() {
		return new Reel(-1 * getValeur());
	}

	@Override
	public ElemGroupe somme(ElemGroupe e) {
		if(e instanceof Reel)
			return new Reel(((Reel) e).n.add(n).doubleValue());
		
		return null;
	}

	public double getValeur() {
		return n.doubleValue();
	}
	
	@Override
	public String toString() {
		return String.valueOf(n);
	}

	@Override
	public int compareTo(Reel o) {
		return n.compareTo(o.n);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj){
			return true;
		}
		
		if(obj instanceof Reel){
			Reel anotherReel = (Reel) obj;
			return anotherReel.n.equals(n);
		}
		
		return false;
	}

}
